﻿using System;
using System.Collections.Generic;
using System.Linq;
using TESTCommons.LinqUtil;
using TestDBData.EFContext;
using TestModel.SysManage;

namespace TestService.SysManage
{
    public partial class Sys_LogService : ISys_LogService
    {
        #region 参数
        private readonly IRepository<sys_Log> _Log;
        #endregion

        #region 构造函数
        public Sys_LogService(IRepository<sys_Log> Log)
        {
            _Log = Log;
        }
        #endregion


        public void AddLog(sys_Log model)
        {
            _Log.Insert(model);
        }

        public void DeleteLog(IEnumerable<sys_Log> models)
        {
            _Log.Delete(models);
        }

        public List<sys_Log> QueryLog(DateTime? fromUtc = null, DateTime? toUtc = null, int pageIndex = 0, int pageSize = int.MaxValue)
        {
            var expression = LinqExtensions.True<sys_Log>();
            if (fromUtc.HasValue)
                expression = expression.And(t => t.createTime >= fromUtc);
            if (toUtc.HasValue)
                expression = expression.And(t => t.createTime <= fromUtc);

            var log = _Log.Table.Where(expression.Compile()).ToList();
            return new TestDBData.EFContext.PagedList<sys_Log>(log, pageIndex, pageSize);
        }
    }
}
